package com.magic.gre.helper;

import android.text.TextUtils;

import com.magic.gre.entity.UserBean;
import com.noname.lib_base_java.util.L;
import com.noname.lib_base_java.util.SharedPrefUtil;
import com.noname.lib_base_java.util.ValidateUtil;

/**
 * Author: Lmoumou
 * Date: 2019-01-10 16:46
 * 文件名: Apphelper
 * 描述:
 */
public class Apphelper {

    public static String phoneDealWith(String phone) {
        if (ValidateUtil.Mobile(phone)) {
            return phone.subSequence(0, 3) + "****" + phone.subSequence(7, 11);
        } else {
            return phone;
        }
    }

    public static boolean isLogin() {
        return !TextUtils.isEmpty(getToken());
    }

    /**
     * 储存Token
     *
     * @param token
     */
    public static void putToken(String token) {
        SharedPrefUtil.open(SharedPrefUtil.NAME).putString("token", token);
    }

    /**
     * 获取Token
     *
     * @return
     */
    public static String getToken() {
        return SharedPrefUtil.open(SharedPrefUtil.NAME).getString("token");
    }

    /**
     * 移除Token
     */
    public static void removeToken() {
        SharedPrefUtil.open(SharedPrefUtil.NAME).remove("token");
    }

    /**
     * 储存用户信息
     *
     * @param userBean
     */
    public static void putUserInfo(UserBean userBean) {
        SharedPrefUtil.open(SharedPrefUtil.NAME).putEntity("user", userBean);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    public static UserBean getUserInfo() {
        return (UserBean) SharedPrefUtil.open(SharedPrefUtil.NAME).getEntity("user");
    }

    /**
     * 移除用户信息
     */
    public static void removeUser() {
        SharedPrefUtil.open(SharedPrefUtil.NAME).remove("user");
    }

    /**
     * 保存是否自动播放声音
     *
     * @param b
     */
    public static void putVoice(boolean b) {
        SharedPrefUtil.open(SharedPrefUtil.NAME).putBoolean("voice", b);
    }

    /**
     * 获取声音开关
     *
     * @return
     */
    public static boolean getVoice() {
        return SharedPrefUtil.open(SharedPrefUtil.NAME).getBoolean("voice");
    }

    /**
     * 移除声音开关
     */
    public static void removeVovice() {
        SharedPrefUtil.open(SharedPrefUtil.NAME).remove("voice");
    }


    /**
     * 存放词本位置
     *
     * @param position
     */
    public static void putThesaurusPosition(int position) {
        L.e("PPPPP", "position->" + position);
        SharedPrefUtil.open(SharedPrefUtil.NAME).putInt("thesaurusposition", position);
    }

    /**
     * 获取词本位置
     */
    public static int getThesaurusPosition() {
        return SharedPrefUtil.open(SharedPrefUtil.NAME).getInt("thesaurusposition", 1000);
    }

    /**
     * 移除词本位置
     */
    public static void removeThesaurusPosition() {
        SharedPrefUtil.open(SharedPrefUtil.NAME).remove("thesaurusposition");
    }


    /**
     * 移除所有信息
     */
    public static void removeAll() {
        removeToken();
        removeUser();
        removeVovice();

    }


}
